package com.ncloud.billing.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.billing.entity.Bill;

@Mapper
public interface BillMapper{

	@Select("SELECT bill_id, cust_id,acct_id, prod_inst_id, prod_id, prod_name, discnt_inst_id, discnt_id, discnt_name,cycle_id, fee, balance, late_fee, late_balance, "
			+ "date_format(latecal_time, '%Y-%m-%d %H:%i:%s' ) as latecal_time, bill_pay_tag,"
			+ "date_format(update_time, '%Y-%m-%d %H:%i:%s' ) as update_time, update_user_id, rsrv_fee1, rsrv_info1, remark "
			+ "FROM bi_d_bill where acct_id=#{acctID} ")
	@Results({
		@Result(column="bill_id",property="bill_id"),@Result(column="acct_id",property="acct_id"),@Result(column="cust_id",property="cust_id"),
		@Result(column="prod_inst_id",property="prod_inst_id"),@Result(column="prod_id",property="prod_id"),
		@Result(column="prod_name",property="prod_name"),@Result(column="discnt_inst_id",property="discnt_inst_id"),
		@Result(column="discnt_id",property="discnt_id"),@Result(column="discnt_name",property="discnt_name"),
		@Result(column="cycle_id",property="cycle_id"),@Result(column="fee",property="fee"),
		@Result(column="balance",property="balance"),@Result(column="late_fee",property="late_fee"),
		@Result(column="late_balance",property="late_balance"),@Result(column="latecal_time",property="latecal_time"),
		@Result(column="bill_pay_tag",property="bill_pay_tag"),
		@Result(column="update_time",property="update_time"),@Result(column="update_user_id",property="update_user_id"),
		@Result(column="rsrv_fee1",property="rsrv_fee1"),@Result(column="rsrv_info1",property="rsrv_info1"),
		@Result(column="remark",property="remark")})
	List<Bill> getBillByAcctID(Long acctID);

	@Update(value = "UPDATE bi_d_bill SET balance = #{balance}, bill_pay_tag = #{bill_pay_tag}, update_time = #{update_time}, update_user_id = #{update_user_id} WHERE bill_id = #{bill_id} ")
    public int updateBill(Bill bill);
	@Insert(value = "INSERT INTO bi_d_bill (bill_id,cust_id,acct_id, prod_inst_id, prod_id, prod_name, discnt_inst_id, discnt_id, discnt_name,cycle_id, fee, balance, late_fee, late_balance,"
			+ "bill_pay_tag,"
			//+ "project_id, contract_inst_id, node_id, item_code, "
			+ "update_time, update_user_id, rsrv_fee1, rsrv_info1, remark) "
	+ "values(#{bill_id},#{cust_id},#{acct_id},#{prod_inst_id}, #{prod_id}, #{prod_name}, #{discnt_inst_id}, #{discnt_id}, #{discnt_name},#{cycle_id},#{fee},#{balance},#{late_fee},"
	+ "#{late_balance},#{bill_pay_tag},"
	//+ "#{project_id},#{contract_inst_id},#{node_id},#{item_code},"
	+ "#{update_time},#{update_user_id},#{rsrv_fee1},#{rsrv_info1},#{remark})")
	public int insertBill(Bill bill);
}
